<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
if($_RQ['op']=='main'){
	$store=pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$this->store_id));
	$store['url']=custom_url('jy_weishop/store.detail//issale=1&id='.$store['id'].'&workerid='.$this->workerid,true);
	$return['store']=$store;
	$avatar=pdo_getcolumn('core_members',array('id'=>$return['item']['mid']),'avatar');
	$return['params']=array('daytype'=>0);
	$return['orderparams']=array('daytype'=>0);
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='getlist'){
	$return['list']=pdo_getall('jy_pinggou_group',array('uniacid'=>$_SESSION['uniacid']));
	$params=$paramsteam=array('uniacid'=>$_SESSION['uniacid']);
	$return['params']=array();
	//创建时间
	if($_RQ['tstart'] && $_RQ['tend']){
		$params['createtime between']=array($_RQ['tstart'],$_RQ['tend']);
		$paramsteam['createtime between']=array($_RQ['tstart'],$_RQ['tend']);
	}else{
		$daytype=intval($_RQ['daytype']);
		if($daytype==0){
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['createtime >']=$daytime;
			$paramsteam['createtime >']=$daytime;
		}elseif($daytype==1){
			$yesdaytime = mktime(0,0,0,date('m'),date('d')-1,date('Y'));
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['createtime between']=array($yesdaytime,$daytime);
			$paramsteam['createtime between']=array($yesdaytime,$daytime);
		}elseif($daytype=2){
			$day7time = mktime(0,0,0,date('m'),date('d')-7,date('Y'));
			$params['createtime >']=$day7time;
			$paramsteam['createtime >']=$day7time;
		}elseif($daytype==3){
			$monthtime = strtotime(date('Y-m',time()));
			$params['createtime >']=$monthtime;
			$paramsteam['createtime >']=$monthtime;
		}elseif($daytype==4){
			$monthtime=strtotime(date('Y-m',time()));
			$startmonthtime = strtotime(date('Y-m',$monthtime-2*24*3600));
			$params['createtime between']=array($startmonthtime,$monthtime);
			$paramsteam['createtime between']=array($startmonthtime,$monthtime);
		}elseif($daytype==5){
			
		}
	}
	foreach($return['list'] as &$item){
		$params['groupid']=$item['id'];
		$params1=$params;
		$params1['type']=3;
		$params1['status']=1;
		$item['fee3']=pdo_getsum('jy_pinggou_log',$params1,'total_price');
		$params2=$params;
		$params2['type']=0;
		$params2['status']=1;
		$item['canyunum']=pdo_count('jy_pinggou_log',$params2,'id');
		$params3=$paramsteam;
		$params3['plugin_name']='jy_pinggou';
		$params3['status']=1;
		$goodsids=pdo_getall('jy_pinggou_goods',array('groupid'=>$item['id']),'goodsid','goodsid');
		if($goodsids){
			$goodsids=array_keys($goodsids);
			$params3['goodsid']=$goodsids;
			$item['teamnum']=pdo_count('jy_weishop_groups_team',$params3,'id');
		}
		$params4=$params;
		$params4['type']=4;
		$item['pingbnumuser']=pdo_count('jy_pinggou_feelog',$params4,'id');
	}
	exi($return);
}
if($_RQ['op']=='getorderlist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$return['params']=array();
	//创建时间
	if($_RQ['tstart'] && $_RQ['tend']){
		$params['createtime between']=array($_RQ['tstart'],$_RQ['tend']);
	}else{
		$daytype=intval($_RQ['daytype']);
		if($daytype==0){
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['createtime >']=$daytime;
		}elseif($daytype==1){
			$yesdaytime = mktime(0,0,0,date('m'),date('d')-1,date('Y'));
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['createtime between']=array($yesdaytime,$daytime);
		}elseif($daytype=2){
			$day7time = mktime(0,0,0,date('m'),date('d')-7,date('Y'));
			$params['createtime >']=$day7time;
		}elseif($daytype==3){
			$monthtime = strtotime(date('Y-m',time()));
			$params['createtime >']=$monthtime;
		}elseif($daytype==4){
			$monthtime=strtotime(date('Y-m',time()));
			$startmonthtime = strtotime(date('Y-m',$monthtime-2*24*3600));
			$params['createtime between']=array($startmonthtime,$monthtime);
		}elseif($daytype==5){
			
		}
	}
	$list=array();
	$params0=$params;
	$params0['ispay']=1;
	$params0['teamid']=0;
	$list[0]=array(
		'title'=>'普通商品流水(非拼团)',
		'num'=>pdo_getsum('jy_weishop_order',$params0,'price')?:0.00,
	);
	$params1=$params;
	$params1['ispay']=1;
	$params1['teamid <>']=0;
	$params1['plugin_name']='jy_pinggou';
	$list[1]=array(
		'title'=>'成功拼团交易金(元)',
		'num'=>pdo_getsum('jy_weishop_order',$params1,'price')?:0.00,
	);
	$params2=$params;
	$params2['ispay']=1;
	$params2['status']=array(1,2,3);
	$params2['teamid <>']=0;
	$params2['plugin_name']='jy_pinggou';
	$list[2]=array(
		'title'=>'参团总人数(人)',
		'num'=>pdo_count('jy_weishop_order',$params2,'id'),
	);
	$params3=$params;
	$params3['status']=1;
	$params3['plugin_name']='jy_pinggou';
	$list[3]=array(
		'title'=>'参团总数(次)',
		'num'=>pdo_count('jy_weishop_groups_team',$params3,'id'),
	);
	$return['list']=$list;
	exi($return);
}